package com.yonyou.cms.epc.controller.graphic;
import com.yonyou.cms.epc.client.dto.graphic.GraphicInfoDTO;
import com.yonyou.cms.epc.client.entity.graphic.GraphicInfoPO;
import com.yonyou.cms.epc.service.graphic.GraphicAssemblyInfoService;
import com.yonyou.cms.epc.service.graphic.GraphicInfoService;
import com.yonyou.cms.epc.service.graphic.GraphicModelService;
import com.yonyou.cms.epc.service.graphic.GraphicSystemService;
import com.yonyou.cyx.framework.util.bean.ApplicationContextHelper;
import com.yonyou.cyxdms.framework.bean.dto.user_info.LoginInfoDto;
import org.springframework.web.bind.annotation.*;
import com.yonyou.cyx.framework.controller.base.BaseController;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 *
 * @author xh
 * @since 2022-06-09
 */
@RestController
@RequestMapping("/graphic/graphicInfo")
public class GraphicInfoController extends BaseController {
    private final Logger logger = LoggerFactory.getLogger(GraphicInfoController.class);

    @Autowired
    public GraphicInfoService graphicInfoService;
    @Autowired
    public GraphicAssemblyInfoService graphicAssemblyInfoService;
    @Autowired
    public GraphicModelService graphicModelService;
    @Autowired
    public GraphicSystemService graphicSystemService;
    /**
     * 分页查询数据
     * @param queryCondition 查询条件
     * @return com.baomidou.mybatisplus.core.metadata.IPage 分页对象
     * @author xh
     * @since 2022-06-09
     */
    @ResponseBody
    @GetMapping
    public IPage<Map<String, Object>> getList(@RequestParam Map<String, Object> queryCondition,
                                              Page<Map<String, Object>> page) {
        return graphicInfoService.selectPageBysql(page, queryCondition);
    }

    /**
     * 进行数据修改
     * @param id 数据主键ID
     * @return  Map<String,Object> 数据对应的map 结构
     * @author xh
     * @since 2022-06-09
     */
    @ResponseBody
    @GetMapping(value="/{id}")
    @SuppressWarnings("unchecked")
    public Map<String,Object> getById(@PathVariable("id") Integer id) {
        return graphicInfoService.getById(id);
    }

    /**
     * 进行数据新增
     * @param graphicInfoDTO 需要保存的DTO
     * @return Map<String,Object> 返回的数据map
     * @author xh
     * @since 2022-06-09
     */
    @ResponseBody
    @PostMapping
    @ResponseStatus(HttpStatus.CREATED)
    @SuppressWarnings("unchecked")
    public Map<String,Object> insert(@RequestBody GraphicInfoDTO graphicInfoDTO) {
        logger.debug("graphicInfoDTO:{}",graphicInfoDTO);
        return graphicInfoService.insert( graphicInfoDTO);
    }

    /**
     * 进行数据修改
     * @param id 需要修改数据的ID
     * @param graphicInfoDTO 需要保存的DTO
     * @return Map<String,Object> 返回的数据map
     * @author xh
     * @since 2022-06-09
     */
    @ResponseBody
    @PutMapping(value="/{id}")
    @ResponseStatus(HttpStatus.CREATED)
    @SuppressWarnings("unchecked")
    public Map<String,Object> update(@PathVariable("id") Integer id, @RequestBody GraphicInfoDTO graphicInfoDTO) {
        logger.debug("graphicInfoDTO:{}",graphicInfoDTO);
        return graphicInfoService.update(id,graphicInfoDTO);
    }

    /**
     * 根据queryParam删除对象
     * @param id
     * @author xh
     * @since 2022-06-09
     */
    @ResponseBody
    @PostMapping(value = "/deleteById/{id}")
    public boolean deleteById(@PathVariable("id") Integer id){
        Map<String, Object> queryParam =new HashMap<>();
        queryParam.put("graphicId",id);
        List<Map<String, Object>>  graphicInfoList =graphicAssemblyInfoService.selectListBySql(queryParam);
        if(graphicInfoList.size()>0){
            return false;
        }else{
            graphicInfoService.deleteById(id);
            return true;
        }
    }
    /**
     * 根据IDs批量删除对象
     * @param ids 需要修改数据的ID集合
     * @author xh
     * @since 2022-06-09
     */
    @DeleteMapping(value="/batch/{ids}")
    @ResponseStatus(HttpStatus.NO_CONTENT)
    public boolean deleteByIds(@PathVariable("ids") String ids){
        logger.debug("删除ID:{}",ids);
        graphicInfoService.deleteBatchIds(ids);
        return true;
    }
    /**
     * 进行下拉框查询(车型)
     * @param
     * @return  ListMap<String,Object> 数据对应的List 结构
     * @author xh
     * @since 2022-06-09
     */
    @RequestMapping(value = "/getGraphicModelList", method = RequestMethod.GET)
    @ResponseBody
    public List<Map<String, Object>> getGraphicModelList(@RequestParam Map<String, Object> queryParam) {
        return graphicModelService.selectListBySql(queryParam);
    }

    /**
     * 进行下拉框查询（系统）
     * @param
     * @return  ListMap<String,Object> 数据对应的List 结构
     * @author xh
     * @since 2022-06-09
     */
    @RequestMapping(value = "/getGraphicSystemList", method = RequestMethod.GET)
    @ResponseBody
    public List<Map<String, Object>> getGraphicSystemList(@RequestParam Map<String, Object> queryParam) {
        LoginInfoDto loginInfo = ApplicationContextHelper.getBeanByType(LoginInfoDto.class);
        queryParam.put("appId",loginInfo.getAppId());
        queryParam.put("statu",30411001);
        return graphicSystemService.selectListBySql(queryParam);
    }



}